package com.anche.cywebnew.Controller.auditManager;

import com.anche.cywebnew.Pojo.auditManager.NasLog;
import com.anche.cywebnew.Pojo.auditManager.StationLog;
import com.anche.cywebnew.Service.auditManager.NasLogService;
import com.anche.cywebnew.Service.auditManager.StationLogService;
import com.github.pagehelper.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/audit/stationLog")
public class StationLogController {

    private static final Logger logger = LoggerFactory.getLogger(StationLogController.class);

    @Autowired
    private StationLogService stationLogService;

    @GetMapping("/manager")
    public String manager(){
        return "auditManager/stationLog";
    }

    @RequestMapping("/stationLogPager")
    @ResponseBody
    public Object getOperateLog(@RequestParam("page") Integer page, @RequestParam("limit") Integer limit,
                                StationLog stationLog, HttpServletRequest request) {
        Map<String, Object> map = new HashMap<>();
        try {
            Page<StationLog> stationLogPager = stationLogService.getStationLogPager(page, limit, stationLog);
            logger.info("<查询站点扫描日志列表成功>");
            map.put("code", "0");
            map.put("count", stationLogPager.getTotal());
            map.put("msg", "查询成功");
            map.put("data", stationLogPager.getResult());
        } catch (Exception e) {
            logger.error("<查询站点扫描日志列表异常:[{}]>", e.getMessage());
            e.printStackTrace();
            map.put("code", "1");
            map.put("msg", e.getMessage());
        }
        return map;
    }
}
